package com.sure.trafficvideo;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.pm.ActivityInfo;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.VideoView;

public class VideoDetailActivity extends Activity {

	private VideoView mVideoView;
	private static final String url = "rtsp://120.196.125.22:554/live/1/B4F8170C5224FAAA/t34GjjIpLQxVuXJJ.sdp?id=13800000098&t=1343810066&en=4bdffc6875ce79cbd01cf158047b3d30&rs=ws";
	private ProgressDialog loadingDialog;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.video_detail);

		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

		loadingDialog = new ProgressDialog(this);
		loadingDialog.setMessage("路况视频正在加载中...");
		loadingDialog.show();

		mVideoView = (VideoView) findViewById(R.id.video_display_view);

		mVideoView.setOnPreparedListener(new OnPreparedListener() {
			@Override
			public void onPrepared(MediaPlayer mp) {
				loadingDialog.dismiss();
			}
		});
		mVideoView.setOnErrorListener(new OnErrorListener() {
			
			@Override
			public boolean onError(MediaPlayer mp, int what, int extra) {
				loadingDialog.dismiss();
				finish();
				return true;
			}
		});
		mVideoView.setVideoPath(url);
		mVideoView.requestFocus();
		mVideoView.start();
	}

}
